/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author Amira
 */
public class BomberMan extends Sprite {

    int p_x;
    int p_y;
    int speed_x;
    int speed_y;
    int[] FRAME_SEQUENCE = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    int[] FRAME_SEQUENCE_EXPLORE = {0, 1, 2, 3, 4, 5, 6};
    boolean alive = true;
    boolean moved = true;
    int initial_Speed = 1;

    public BomberMan(int x, int y) throws IOException {
        super(Image.createImage("/resource/bomber.png"), 20, 20);

        System.out.println("constructor0000000000000000000000000000000000000000000000");
        p_x = x;
        p_y = y;
        speed_x = 20 * x;
        speed_y = 20 * y + 51;
        defineReferencePixel(0, 0);
        setRefPixelPosition(speed_x, speed_y);
        setFrameSequence(FRAME_SEQUENCE);
        setFrame(2);

    }

    public void bomber_die() {
        alive = false;
        moved = true;
        try {
            setImage(Image.createImage("/resource/bomber_explore.png"), 20, 20);
            defineReferencePixel(0, 0);
            setRefPixelPosition(speed_x, speed_y);
            setFrameSequence(FRAME_SEQUENCE_EXPLORE);
            setFrame(0);

        } catch (Exception e) {
        }

    }

    public void StopMove() {
        moved = false;
        setFrame(2);
    }

    public void up() {
        System.out.println("uppppppppppppppppppppppppppp");
        moved = true;
        speed_y-= initial_Speed;
        setPosition(speed_x, speed_y);
        if (getFrame() >= 5 || getFrame() < 2) {
            setFrame(2);
        }

    }

    public void down() {
        moved = true;
        speed_y += initial_Speed;
        setPosition(speed_x, speed_y);
        if (getFrame() >= 2 && getFrame() < 11) {
            setFrame(11);
        }
    }

    public void right() {
        moved = true;
        speed_x += initial_Speed;
        if (getFrame() >= 11 || getFrame() < 8) {
            setFrame(8);
        }
        setPosition(speed_x, speed_y);

    }

    public void left() {
        moved = true;
        speed_x -= initial_Speed;
      if(getFrame()>=8 || getFrame()<5)
            setFrame(5);
        setPosition(speed_x, speed_y);
    }

    public void move() {
        if (alive) {
            if (moved) {
                nextFrame();
            } else {
                setFrame(2);
            }
        } else {
            if (getFrame() == 6) {
                setFrame(6);
                moved = false;
            }

            nextFrame();
        }
    }
}
